import { createRouter,createWebHashHistory } from "vue-router";



const routes=[
    {
        path:'/',
        redirect:'/recommend',
    },
    {
        path: '/recommend',
        name: 'recommend',
        component: () => import('../views/recommend'),
        meta: {
            title: '推荐'
        },
    },
    {
        path: '/singer',
        name: 'singer',
        component: () => import('../views/singer'),
        meta: {
            title: '歌手'
        },
    },
    {
        path: '/singerDetail',
        name: 'singerDetail',
        component: () => import('../views/singer-detail'),
        meta: {
           title: '详情'
        }
    },
    {
        path: '/search',
        name: 'search',
        component: () => import('../views/search'),
        meta: {
            title: '搜索'
        }
    },
    {
        path: '/list',
        name: 'list',
        component: () => import('../views/list'),
        meta: {
            title: '排行'
        }
    },

]

const router = createRouter({
    history:createWebHashHistory(process.env.BASE_URL),
    routes
})

//全局前置路由守卫
router.beforeEach((to, from, next) => {
    //const tokenStr = utils.localGetItem('token');
    // let paths = to.path
    // if (paths.includes('uc')) {
    //     if (!tokenStr) {
    //         alert('你还没有登录')
    //         return next('/login');
    //     }
    // }
    // if (to.path === '/login') return next();
    next()
});


router.afterEach((to)=>{
    document.title=to.meta.title
})

export default router
